Repository navigation
Fix a bug that caused the display ratio of images to be corrupted starting from 6.3.( fix #53555 ) - #53598
Fix a bug that caused the display ratio of images to be corrupted starting from 6.3.( fix #53555 )#53598ddryo wants to merge 1 commit into
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
@scruffian Since you reviewed the similar #53274, could we get your eyes on this one, too? |
|
@MaggieCabrera Is this what we observed with our testing earlier this week when that one image didn't show the controls? |
It could be happening that after we use "Replace" on an existing image (this is the code for the original image in TT4) the dimensions are added to the block and that makes aspect ratio fail |
| // Note that only width may be "auto". | ||
| if ( ! aspectRatio && height && width && 'auto' !== width ) { |
There was a problem hiding this comment.
height can be set to auto in the editor with a fixed width, so we can't make this assumption here. We want to support layouts where that is required.
There was a problem hiding this comment.
If migrate needs to be added to all these deprecations, that seems to me like a bug in applyBlockDeprecatedVersions, not the image block deprecations. The documentation for block deprecations doesn't mention this, and it seems rather awkward and error-prone to have to add them everywhere.
| const w = parseInt( width ); | ||
| const h = parseInt( height ); |
There was a problem hiding this comment.
The idea for the image block moving forward is to support units other than px, so we don't want to parseInt without confirming that they are pixel values first.
| if ( ! aspectRatio && height && width && 'auto' !== width ) { | ||
| const w = parseInt( width ); | ||
| const h = parseInt( height ); | ||
| if ( ! isNaN( w ) && ! isNaN( h ) ) { | ||
| imgStyle.aspectRatio = `${ w }/${ h }`; | ||
| } | ||
| } else { | ||
| if ( 'string' === typeof width ) imgStyle.width = width; | ||
| if ( 'string' === typeof height ) imgStyle.height = height; | ||
| } |
There was a problem hiding this comment.
The logic here should be moved to edit.js to allow for more flexibility of styling.
What?
Since 6.3, there is a bug that the display ratio is broken when the size is specified in the image block. (#53555)
This PR fixes the above problem.
How?
If both
widthandheighthave size specifications, they are converted toaspect-ratiorather than being output as they are in thestyleattribute.Testing Instructions
As an example, I share one image block code I installed in 6.2.
Note
There was already a PR for 53274 that fixes another problem, which was already different from the 6.3 situation.
The 53274 changed the
width,heightto astringtype, but blocks placed before 6.2 were not migrated correctly to astringtype, so we are fixing those as well.(In
deprecated.js,migrateprocess was also added tov6~v4)